﻿/**
 * 移动速度
 * @type Number
 */
var scrlSpeed=1

/**
 * document.all判断是否是IE浏览器
 * @type 
 */
scrlSpeed=(document.all)? scrlSpeed : Math.max(1, scrlSpeed-1);

/**
 * 
 * @param {} container显示滚动内容的区域
 * @param {} object要滚动的内容
 */
function initScroll(container,object){
    if (document.getElementById(container) != null){
        var contObj=document.getElementById(container);
        var obj=document.getElementById(object);
        contObj.style.visibility = "visible";	//容器可见
        contObj.scrlSpeed = scrlSpeed;
        widthContainer = contObj.offsetWidth;	//容器包括边线的宽度
        obj.style.left=parseInt(widthContainer)+"px";//滚动内容左边位置
        widthObject=obj.offsetWidth;
        interval=setInterval("objScroll('"+ container +"','"+ object +"',"+ widthContainer +")",20);
        contObj.onmouseover = function(){
            contObj.scrlSpeed=0;
        }
        contObj.onmouseout = function(){
            contObj.scrlSpeed=scrlSpeed;
        } 
    }
}

function objScroll(container,object,widthContainer){
    var contObj=document.getElementById(container);
    var obj=document.getElementById(object);
    widthObject=obj.offsetWidth;
    if (parseInt(obj.style.left)>(widthObject*(-1))){
        obj.style.left=parseInt(obj.style.left)-contObj.scrlSpeed+"px";
    } else {
        obj.style.left=parseInt(widthContainer)+"px";
    }
}

window.onload=function(){ 
    initScroll("scrlContainer", "scrlContent");
}